package guoanmaker.provider.business.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.provider.business.service.DataStatisticsServiceInterface;
import guoanmaker.provider.helper.common.AjaxJson;
import guoanmaker.provider.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(ApiController.DATASTATISTICS_URL)
public class DataStatisticsController {

	
	@Autowired
	private DataStatisticsServiceInterface dataStatisticsServiceInterface;
	
	@ApiOperation(value="查询服务商的数据统计的定值", notes="查询服务商的数据统计的定值")
	@PostMapping("/routineData")
	public AjaxJson routineData(String businessId){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(dataStatisticsServiceInterface.routineData(businessId));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="根据天数查询销量走势", notes="根据天数查询销量走势")
	@PostMapping("/salesTrend")
	public AjaxJson salesTrend(String businessId,Integer time){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(dataStatisticsServiceInterface.salesTrend(businessId,time));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="查询近一年销量走势", notes="查询近一年销量走势")
	@PostMapping("/salesTrendInThePastYear")
	public AjaxJson salesTrendInThePastYear(String businessId){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(dataStatisticsServiceInterface.salesTrendInThePastYear(businessId));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
}
